import { base_url } from './config.js';
import { getToken } from '../util/tool.js';

export const job = {
	// 懒加载获取推荐职位接口
	async getAllJob(lastJobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/getAllJob',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { lastJobId },
				success(res) {
					console.log('【 Response in request getAllJob 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request getAllJob 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 获取职位详情接口
	async getJobDetail(jobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/getJobDetail?jobId=' + jobId,
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				success(res) {
					console.log('【 Response in request getJobDetail 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request getJobDetail 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 查询是否收藏岗位接口
	async isCollectJob(jobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/isCollectJob',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { jobId },
				success(res) {
					console.log('【 Response in request isCollectJob 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request isCollectJob 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 添加收藏岗位接口
	async collectJob(jobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/collectJob',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { jobId },
				success(res) {
					console.log('【 Response in request collectJob 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request collectJob 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 取消收藏岗位接口
	async delCollectJob(jobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/delCollectJob',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { jobId },
				success(res) {
					console.log('【 Response in request delCollectJob 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request delCollectJob 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 添加个人简历接口
	async addResume(name, eduBackground, position, email, phone, college, studyingTime, major, professional, projExperience, workExperience) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/addResume',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: {
					name, eduBackground, position, email, phone, college, studyingTime, major, professional, projExperience, workExperience
				},
				success(res) {
					console.log('【 Response in request addResume 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request addResume 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 获取个人简历接口
	async getResume() {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/getResume',
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				success(res) {
					console.log('【 Response in request getResume 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request getResume 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 修改个人简历接口
	async updateResume(name, eduBackground, position, email, phone, college, studyingTime, major, professional, projExperience, workExperience) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/updateResume',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: {
					name, eduBackground, position, email, phone, college, studyingTime, major, professional, projExperience, workExperience
				},
				success(res) {
					console.log('【 Response in request updateResume 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request updateResume 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 岗位投递接口
	async resumeSubmission(jobId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/resumeSubmission',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { jobId },
				success(res) {
					console.log('【 Response in request resumeSubmission 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request resumeSubmission 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 删除岗位投递记录接口
	async delResumeSubmission(resumeSubmissionId) {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/delResumeSubmission',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				data: { resumeSubmissionId },
				success(res) {
					console.log('【 Response in request delResumeSubmission 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request delResumeSubmission 】', err);
					reject({ success: false });
				}
			});
		});
	},
	// 获取所有岗位投递记录接口
	async getAllResumeSubmission() {
		let jwt = getToken();
		return new Promise((resolve, reject) => {
			uni.request({
				url: base_url + '/job/getAllResumeSubmission',
				method: 'GET',
				header: {
					'content-type': 'application/json',
					'Authorization': jwt
				},
				success(res) {
					console.log('【 Response in request getAllResumeSubmission 】', res);
					resolve(res.data);
				},
				fail(err) {
					console.log('【 Error in request getAllResumeSubmission 】', err);
					reject({ success: false });
				}
			});
		});
	},
};
